<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-form-item label="泳池名称" prop="poolName">
        <el-input v-model="form.poolName" placeholder="请输入泳池名称" />
      </el-form-item>
	  <el-form-item label="泳池照片" required>
			<FileUpload
				@input='inputFile'
				:value="fileList"
				:fileType="['png', 'jpg', 'jpeg']"
			>
			</FileUpload>
	  </el-form-item>
		<el-form-item label="泳池描述" prop="poolDesc">
		  <el-input v-model="form.poolDesc" placeholder="请输入泳池描述" type="textarea" />
		</el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </div>
  </div>
</template>

<script>
import FileUpload from '@/components/FileUpload'	
import { mapGetters, mapState } from "vuex";
import { 
	insert,
	edit,
	detail,
} from "@/api/swimming/index";
import { strchangeArr } from "@/utils/index";
export default {
  name: "Post",
  data() {
    return {
	  id:'',
	  fileList:[],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        poolName: [
          { required: true, message: "泳池不能为空", trigger: "blur" }
        ],
		poolDesc: [
		  { required: true, message: "泳池描述不能为空", trigger: "blur" }
		]
      }
    };
  },
  computed: {
    
  },
  created() {
	this.getPoor()
  },
  methods: {
	//获取泳池详情
	getPoor(){
		detail({poolName:''}).then(response => {
		   this.form = response.data
		   this.fileList = response.data.images 
		});
	},
	// 覆盖默认的上传行为
	requestUpload() {},
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
	//获取上传图片
	inputFile(file){
		this.form.images = file
	},
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id) {
            edit(this.form).then(response => {  
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            insert(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  }
};
</script>
